package org.pada.client.dto;

import org.pada.client.exception.ErrorCode;

/**
 * @author pengshen
 * @date 2023.12.29 17:59
 */
public class Resp implements DTO {

    private static final long serialVersionUID = 1L;

    private boolean success;

    private String errCode;

    private String errMessage;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getErrCode() {
        return errCode;
    }

    public void setErrCode(String errCode) {
        this.errCode = errCode;
    }

    public String getErrMessage() {
        return errMessage;
    }

    public void setErrMessage(String errMessage) {
        this.errMessage = errMessage;
    }

    @Override
    public String toString() {
        return "Response [success=" + success + ", errCode=" + errCode + ", errMessage=" + errMessage + "]";
    }

    public static Resp buildSuccess() {
        Resp resp = new Resp();
        resp.setSuccess(true);
        return resp;
    }

    public static Resp buildFailure(ErrorCode errorCode) {
        Resp resp = new Resp();
        resp.setSuccess(false);
        resp.setErrCode(errorCode.getErrCode());
        resp.setErrMessage(errorCode.getErrMsg());
        return resp;
    }

    public static Resp buildFailure(String errCode, String errMessage) {
        Resp resp = new Resp();
        resp.setSuccess(false);
        resp.setErrCode(errCode);
        resp.setErrMessage(errMessage);
        return resp;
    }
}
